package cn.hpclub.server.validator.admin;

import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

import cn.hpclub.server.model.TariffClass;

public class TariffClassValidator extends Validator{

    @Override
    protected void validate(Controller c){
        //validateRequiredString("tariffClass.name", "tariffClassNameMessages", "大类名称不能为空");

        // System.out.println(c.getParaToInt("tariffClass.id", 0) + ":" +
        // TariffClass.NAME + ":"
        // + c.getPara("tariffClass.name"));

        this.setShortCircuit(true);
        if(!TariffClass.dao.checkUnique(c.getParaToInt("tariffClass.id", 0), TariffClass.NAME,
                                        c.getPara("tariffClass.name"))){
            addError("tariffClassNameMessages", "大类名称已存在");

        }

        this.setShortCircuit(false);
    }

    @Override
    protected void handleError(Controller c){
        c.keepModel(TariffClass.class);
        //c.setAttr("activityTariffClassRelationList", c.getPara("class.enabled"));
        c.render("/admin/tariff_class_add.tpl");
    }
}
